package com.csot.ry.service.impl;

import java.util.List;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.StrUtil;
import com.csot.common.exception.ServiceException;
import com.csot.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.csot.ry.mapper.TCoarseIpMapper;
import com.csot.ry.domain.TCoarseIp;
import com.csot.ry.service.ITCoarseIpService;

/**
 * 粗粒度ip明细Service业务层处理
 * 
 * @author 刘沙
 * @date 2022-05-31
 */
@Service
public class TCoarseIpServiceImpl implements ITCoarseIpService 
{
    @Autowired
    private TCoarseIpMapper tCoarseIpMapper;

    /**
     * 查询粗粒度ip明细
     * 
     * @param id 粗粒度ip明细主键
     * @return 粗粒度ip明细
     */
    @Override
    public TCoarseIp selectTCoarseIpById(Long id)
    {
        return tCoarseIpMapper.selectTCoarseIpById(id);
    }

    /**
     * 查询粗粒度ip明细列表
     * 
     * @param tCoarseIp 粗粒度ip明细
     * @return 粗粒度ip明细
     */
    @Override
    public List<TCoarseIp> selectTCoarseIpList(TCoarseIp tCoarseIp)
    {
        try {
            if (StrUtil.isNotEmpty(tCoarseIp.getIpStart())) {
                tCoarseIp.setIpStartI(NetUtil.ipv4ToLong(tCoarseIp.getIpStart()));
            }
            if (StrUtil.isNotEmpty(tCoarseIp.getIpEnd())) {
                tCoarseIp.setIpEndI(NetUtil.ipv4ToLong(tCoarseIp.getIpEnd()));
            }
        }catch (Exception e){
            throw new ServiceException("起止IP不正确");
        }
        return tCoarseIpMapper.selectTCoarseIpList(tCoarseIp);
    }

    /**
     * 新增粗粒度ip明细
     * 
     * @param tCoarseIp 粗粒度ip明细
     * @return 结果
     */
    @Override
    public int insertTCoarseIp(TCoarseIp tCoarseIp)
    {
        tCoarseIp.setCreateTime(DateUtils.getNowDate());
        return tCoarseIpMapper.insertTCoarseIp(tCoarseIp);
    }

    /**
     * 修改粗粒度ip明细
     * 
     * @param tCoarseIp 粗粒度ip明细
     * @return 结果
     */
    @Override
    public int updateTCoarseIp(TCoarseIp tCoarseIp)
    {
        tCoarseIp.setUpdateTime(DateUtils.getNowDate());
        return tCoarseIpMapper.updateTCoarseIp(tCoarseIp);
    }

    /**
     * 批量删除粗粒度ip明细
     * 
     * @param ids 需要删除的粗粒度ip明细主键
     * @return 结果
     */
    @Override
    public int deleteTCoarseIpByIds(Long[] ids)
    {
        return tCoarseIpMapper.deleteTCoarseIpByIds(ids);
    }

    /**
     * 删除粗粒度ip明细信息
     * 
     * @param id 粗粒度ip明细主键
     * @return 结果
     */
    @Override
    public int deleteTCoarseIpById(Long id)
    {
        return tCoarseIpMapper.deleteTCoarseIpById(id);
    }
}
